package com.itheima.health.service.impl;

import com.itheima.health.dao.MemberDao;
import com.itheima.health.entity.OrderInfo;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Member;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    @Override
    public Member findByTelephone(String phone) {
        return memberDao.findByTelephone(phone);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public List<Setmeal> getSetmeal() {
        List<Setmeal>setmealList = memberDao.getSetmeal();
        return setmealList;
    }
    @Override
    public Setmeal findById(Integer id) {
        Setmeal setmeal = memberDao.findById(id);
        List<CheckGroup> checkGroupList = memberDao.selctcheckGroupsBySetmealId(id);
        for (CheckGroup checkGroup : checkGroupList) {
            List<CheckItem> checkItemList = memberDao.selctCheckItemsByCheckGroupId(checkGroup.getId());
            checkGroup.setCheckItems(checkItemList);
        }
        setmeal.setCheckGroups(checkGroupList);
        return setmeal;
    }

    @Override
    public OrderInfo findOrderById(Integer id) {
        OrderInfo orderInfo = memberDao.findMember(id);
        return orderInfo;
    }
}

